#pragma once
#include "IUpdateable.hpp"
#include "SFML\System\Time.hpp"

namespace rh
{
	class ITransformable;

	class IAnimateable : IUpdateable
	{
	public:
		enum AnimationState
		{
			Initialized,
			Running,
			Completed
		};
	protected:
		AnimationState _animationState;
		rh::ITransformable* _target;
		sf::Time _animationTime;
		sf::Time _animationElapsedTime;

	public:
		IAnimateable(rh::ITransformable* target, sf::Time animationTime) : _target(target), _animationTime(animationTime)
		{ 
		};

		~IAnimateable() { };
		virtual void Start(void)
		{
			_animationState = AnimationState::Running;
			_animationElapsedTime = sf::Time::Zero;
		};

		virtual void Update(const sf::Time& elapsedTime, const sf::Time& totalElapsedTime)
		{
			switch(_animationState)
			{
			case AnimationState::Running:

				Animate(elapsedTime);
				_animationElapsedTime += elapsedTime;
				if(_animationElapsedTime >= _animationTime)
				{
					_animationState = AnimationState::Completed;
					CleanupAnimation();
				}
				break;
			}
		};

		virtual void Animate(const sf::Time& elapsedTime) = 0;
		virtual void CleanupAnimation(void) = 0;

		virtual AnimationState GetAnimationState() { return _animationState; };

		virtual float GetElapsedPercentage() { return _animationElapsedTime.asMilliseconds() / _animationTime.asMilliseconds(); };
	};
}